<?php
    $this->headTitle($this->site_name.' - Admin Home');
?>

<script type="text/javascript" src="/js/ui/jquery.ui.core.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.widget.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.mouse.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.draggable.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.droppable.min.js"></script>
<script type="text/javascript" src="/js/ui/jquery.ui.sortable.min.js"></script>
<script type="text/javascript" src="/js/jquery.validate.js"></script>

<style>
	.draggable1, .draggable2 { cursor:pointer;}
	.sortable { list-style-type: none; margin: 0; padding: 0;  }
	.sortable li { margin: 0 3px 3px 3px;  }
	.sortable li a { position: absolute;  }
	div .left-column { width: 47%; font-size:12px;float:left;}
	div .right-column { width: 47%; font-size:12px;float:left;}
	
</style>

<script>
<?php
	echo "var services=new Array();\n";
	echo "var departments=new Array();\n";
	echo "var serviceurl=new Array();\n";
	$all_services = $this->all_services;
	foreach ($all_services as $key => $value){
		echo "services['".$value['icon']."']='".$value['dpt_name']."';\n";
		echo "departments['".$value['icon']."']='".$value['dpt_id']."';\n";
		echo "serviceurl['".$value['icon']."']='".$value['service_url']."';\n";
	} 
?>

	function addNewUser(){
    	$("#email").val('');
    	$("#password").val('');
    	$("#password2").val('');
    	
		$("span.ui-dialog-title").text('Add New User');  		
		$("#submit").val('Add User');
		$("#user-dialog").dialog("open");
	}		

	function updateUser(id){
		
	    $.post("/default/do/get-user", {id: ""+id+""}, function(data)
	   	{
	    	        if(data['id'] >0) {
		    	    	$("#user_id").val(data['id']);
		    	    	$("#email").val(data['email']);
		    	    	$("#password").val('**********');
		    	    	$("#password2").val('**********');
		    	    	$("#role").val(data['role']);
		    	    	$("#timezone").val(data['timezone']);

	    	        	//alert(content);
	    	    		$("span.ui-dialog-title").text('Update User');  		
	    	    		$("#submit").val('Update User');
	    	    		$("#user-dialog").dialog("open");
	    	        }else{
		    	        alert("Sorry, failed to fetch user information.");
	    			}
	    }, "json");
		
	}		
</script>

<script type="text/javascript">   
	$.validator.addMethod('samePassword', 
	    function (value) {
	    	var pass1=$("#password").val();
	    	if (value==pass1)
		    	return true;
	    	else  
	        	return false; 
	    }, 'password should be the same'); 


	$(document).ready(function(){
	    $("#userForm").validate({
	      rules: {
        	email: {
	          required: true,
	          email: true
	        },
        	password: {
		      required: true
		    },
        	password2: {
		      required: true,
		      samePassword: true
			}
	      },
	      messages: {
	    	email: {
	          required: "Email can not be empty",
	          email: "Email must be valid"
	        },
	        password: {
	          required: "Password can not be empty"
	        },
	        password2: {
		      required: "Password can not be empty"
		    }
	      }
	    });

		$("#user-dialog").dialog({autoOpen:false,modal:true,width:500});
		$( "#sortable1" ).sortable();
		$( "#sortable1" ).disableSelection();
		
		$( ".draggable2" ).draggable({revert: true});		  
	    
	  });

</script>  

<?php if (!empty($this->success_msg)):?>
<div class="response-msg success ui-corner-all"><?php echo $this->success_msg;?></div>
<?php endif ?>

<?php if (!empty($this->error_msg)):?>
<div class="response-msg error ui-corner-all"><?php echo $this->error_msg;?></div>
<?php endif ?>


<div id="admin-dashboard">

<h2>Admin Home</h2>
 
<div class="section">
<h3>Welcome to Yesup central account admin area:</h3>

<div class="demo-frame1" id="droppable1">		

	<ul id="sortable1">
	<li><a href="/admin/client" style="font-size:12px;font-weight:bold;">Clients Management</a></li>
	<li><a href="/admin/message" style="font-size:12px;font-weight:bold;">Central Message Management</a></li>
	<li><a href="/admin/news" style="font-size:12px;font-weight:bold;">News Management</a></li>
	<!-- li><a href="/admin/service" style="font-size:12px;font-weight:bold;">Services Management</a></li-->
<?php if ($this->admin_user_name=='ericli@yesup.com') : ?>
	<li><a href="/admin/user" style="font-size:12px;font-weight:bold;">Admin Users Management</a></li>
<?php endif ?>
	</ul>

</div>
 
</div>


<div class="section">
<div style="margin-left:80px;">
<h3>Yesup services:</h3>

<div class="demo-frame1" id="droppable2">		

	<ul>

	<?php 
	foreach($this->all_services as $index => $item ){
		echo '<li id="'.$item['icon'].'" class="draggable2"><div id="'.$item['icon'].'_div" onclick="window.open(\''.$item['service_url'].'\')"><a href="#">'.$item['dpt_name'].'</a><span id="'.$item['icon'].'_span"></span><p>'.$item['description'].'</p></div></li>';
	}
	?>
	</ul>


</div>
</div>
 
</div>


<input type=hidden name=service_id id=service_id value=''>

<div id="user-dialog" title="Add New User" style="display:none;" >
            <?php if (!empty($this->formError)): ?>
            <div class="form_errors_block">
                <?php echo $this->formError; ?>
            </div>
            <?php endif; ?>

            <?php echo $this->form; ?>
</div>


</div>